home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / GLYPHBTN.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  249 lines

  1. //-------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.19  $
  6. //
  7. // Definition of class TGlyphButton
  8. //-------------------------------------------------------------------------
  9. #if !defined(OWL_GLYPHBTN_H)
  10. #define OWL_GLYPHBTN_H
  11.  
  12. // Macro defining class name (usable in resource definition)
  13. //
  14. #if !defined(OWL_GLYPHBTN)
  15. # define OWL_GLYPHBTN  "OWL_GlyphBtn"
  16. #endif
  17.  
  18. #if !defined(RC_INVOKED)
  19.  
  20. #if !defined(OWL_BUTTON_H)
  21. # include <owl/button.h>
  22. #endif
  23. #if !defined(OWL_UIHELPER_H)
  24. # include <owl/uihelper.h>
  25. #endif
  26. #if !defined(OWL_BITSET_H)
  27. # include <owl/bitset.h>
  28. #endif
  29. #if !defined(WINSYS_COLOR_H)
  30. # include <winsys/color.h>
  31. #endif
  32.  
  33. #if defined(BI_NAMESPACE)
  34. namespace OWL {
  35. #endif
  36.  
  37. // Generic definitions/compiler options (eg. alignment) preceeding the
  38. // definition of classes
  39. #include <services/preclass.h>
  40.  
  41. class _OWLCLASS TFont;
  42.  
  43. //
  44. //
  45. // class TBtnBitmap
  46. // ~~~~~ ~~~~~~~~~~
  47. // TBtnBitmap is an enhanced version of TBitmap with the ability to update
  48. // the face color of a bitmap to match the current system BTNFACE color.
  49. //
  50. class _OWLCLASS TBtnBitmap : public TBitmap {
  51.   public:
  52.     TBtnBitmap(HINSTANCE hInstance, TResId resId,
  53.                const TColor& faceColor = DefaultFaceColor);
  54.     TBtnBitmap(HBITMAP hBitmap,
  55.                const TColor& faceColor = DefaultFaceColor,
  56.                TAutoDelete autoDelete = NoAutoDelete);
  57.  
  58.     void        UpdateFaceColor();
  59.     static void MapColor(TDC& dc, TDC& srcDC, const TColor& toColor,
  60.                          const TColor& fromColor, int width, int height);
  61.  
  62.     // By default, we'll assume that bitmaps were designed with a gray background
  63.     //
  64.     static TColor DefaultFaceColor;
  65.  
  66.   protected:
  67.     TColor      FaceColor;    // Current face color of bitmap
  68. };
  69.  
  70. //
  71. // class TGlyphButton
  72. // ~~~~~ ~~~~~~~~~~~~
  73. // TGlyphButton encapsulates a control which is capable of displaying a
  74. // bitmap (or glyph) and/or text.
  75. //
  76. class _OWLCLASS TGlyphButton : public TButton  {
  77.   public:
  78.     TGlyphButton(TWindow*        parent,
  79.                  int             id,
  80.                  const char far* text,
  81.                  int X, int Y, int W, int H,
  82.                  bool            isDefault = false,
  83.                  TModule*        module = 0);
  84.     TGlyphButton(TWindow* parent, int resourceId, TModule* module = 0);
  85.    ~TGlyphButton();
  86.  
  87.     // Enumeration describing the state when a particular bitmap should
  88.     // be displayed. Used with the 'SetGlyph' method.
  89.     // NOTE: If only a single 'up' bitmap is specified, TGlyphBtn will
  90.     //       automatically generate the bitmaps for the other states.
  91.     //
  92.     enum TGlyphType {
  93.       gtUp       = TUIFace::Normal,   // Bitmap for when button is up
  94.       gtDisabled = TUIFace::Disabled, // Bitmap for when button is disabled
  95.       gtDown,                         // Bitmap for when button is depressed
  96.       gtFocus                         // Bitmap for when button has focus
  97.     };
  98.  
  99.     // Methods to specify the glyphs that should be used
  100.     //
  101.     void      SetGlyph(TBitmap* bitmap, TGlyphType = gtUp);
  102.     void      SetGlyph(TResId resId, TModule* module = 0, TGlyphType = gtUp);
  103.     void      SetGlyph(HBITMAP hBitmap, TGlyphType = gtUp,
  104.                        TAutoDelete autoDelete = NoAutoDelete);
  105.  
  106.     // Enumeration describing how to position the text and glyph
  107.     // of the button.
  108.     //
  109.     enum  TLayoutStyle {
  110.       lsNone,                   // Use specified coordinates
  111.  
  112.       // Horizontal layouts [center vertically]
  113.       //
  114.       lsH_SGST,                 // Space Glyph Space Text
  115.       lsH_GST,                  // Glyph Space Text
  116.     };
  117.  
  118.     // Methods to specify how the glyph and/or text should be laid out
  119.     //
  120.     void      SetLayoutStyle(TLayoutStyle style);
  121.     void      SetTextOrigin(int x, int y);
  122.     void      SetGlyphOrigin(int x, int y);
  123.  
  124.     // Set, clear, query flags about the state of the control
  125.     //
  126.     int       Clear(int t);
  127.     int       Set(int t);
  128.     bool      IsSet(int t) const;
  129.  
  130.   protected:
  131.     // Overriden TWindow virtuals
  132.     //
  133.     void      SetupWindow();
  134.     void      Paint(TDC& dc, bool erase, TRect& rect);
  135.     void      GetWindowClass(WNDCLASS& wndClass);
  136.     char far* GetClassName();
  137.  
  138.     // Routine which determines location of text and glyph
  139.     //
  140.     virtual void LayoutTextGlyph(const TRect& faceRect, TRect& textRect,
  141.                                  TRect& glyphRect);
  142.     // Initialization routine
  143.     //
  144.     void      InitVars();
  145.  
  146.     // Enumeration describing the current state of the button.
  147.     //
  148.     enum  TButtonInfo {
  149.       biPushed   = 0x0001,      // Button is currently depressed
  150.       biFocus    = 0x0002,      // Button has focus
  151.       biDefault  = 0x0004,      // Button is a 'DefaultPushButton'
  152.       biDisabled = 0x0008,      // Button is disabled
  153.       biShowText = 0x0010,      // Button should display its caption
  154.       biShowGlyph= 0x0020       // Button should draw its glyph
  155.     };
  156.  
  157.     // Event handlers
  158.     //
  159.     void        EvPaint();
  160.     bool        EvEraseBkgnd(HDC);
  161.     void        EvSetFocus(THandle hWndLostFocus);
  162.     void        EvKillFocus(THandle hWndGetFocus);
  163.     HFONT       EvGetFont();
  164.     void        EvSetFont(HFONT hFont, bool redraw);
  165.     uint        EvGetDlgCode(MSG far* msg);
  166.     void        EvLButtonDown(uint modKeys, TPoint& point);
  167.     void        EvLButtonDblClk(uint modKeys, TPoint& point);
  168.     void        EvLButtonUp(uint modKeys, TPoint& point);
  169.     void        EvMouseMove(uint modKeys, TPoint& point);
  170.     void        EvKeyDown(uint key, uint repeatCount, uint flags);
  171.     void        EvKeyUp(uint key, uint repeatCount, uint flags);
  172.     void        EvEnable(bool enabled);
  173.     void        EvCancelMode();
  174.     TResult     BmGetState(TParam1 param1, TParam2 param2);
  175.     TResult     BmSetState(TParam1 param1, TParam2 param2);
  176.     TResult     BmSetStyle(TParam1 param1, TParam2 param2);
  177.  
  178.     // Helper functions
  179.     //
  180.     void        PaintNow();
  181.     void        PaintButton(TDC& dc);
  182.     void        PaintFrame(TDC& dc, TRect& rect);
  183.     void        PaintDefaultRect(TDC& dc, TRect& rect);
  184.     void        PaintFace(TDC& dc, TRect& rect);
  185.     void        PaintFocusRect(TDC& dc, const TRect& faceRect);
  186.     void        ClearCapture();
  187.  
  188.   private:
  189.     // Hidden to prevent accidental copying or assignment
  190.     //
  191.     TGlyphButton(const TGlyphButton&);
  192.     TGlyphButton& operator =(const TGlyphButton&);
  193.  
  194.     TBitmap*        UpBmp;          // Pointer to 'normal' glyph
  195.     TBitmap*        DownBmp;        // Pointer to 'pushed' glyph
  196.     TBitmap*        FocusBmp;       // Pointer to 'focused' glyph
  197.     TBitmap*        DisabledBmp;    // Pointer to disabled' glyph
  198.     TFont*          BtnFont;        // Pointer to font used by button
  199.     int             xGlyph;         // x (left) coordinate of glyph
  200.     int             yGlyph;         // y (top ) coordinate of glyph
  201.     int             xText;          // x (left) coordinate of text
  202.     int             yText;          // y (top ) coordinate of text
  203.     TLayoutStyle    LayStyle;       // How text & glyph should be laid out
  204.     TBitFlags<int>  Flags;          // Status flags
  205.   DECLARE_RESPONSE_TABLE(TGlyphButton);
  206. };
  207.  
  208. // Generic definitions/compiler options (eg. alignment) following the
  209. // definition of classes
  210. #include <services/posclass.h>
  211.  
  212. #if defined(BI_NAMESPACE)
  213. } // namespace OWL
  214. #endif
  215.  
  216. //----------------------------------------------------------------------------
  217. // Inline implementations
  218. //
  219.  
  220. //
  221. // Clear a flag
  222. //
  223. inline int
  224. TGlyphButton::Clear(int t)
  225. {
  226.   return Flags.Clear(t);
  227. }
  228.  
  229. //
  230. // Set a flag
  231. //
  232. inline int
  233. TGlyphButton::Set(int t)
  234. {
  235.   return Flags.Set(t);
  236. }
  237.  
  238. //
  239. // Test if a flag is set
  240. //
  241. inline bool
  242. TGlyphButton::IsSet(int t) const
  243. {
  244.   return Flags.IsSet(t);
  245. }
  246.  
  247. #endif  // !RC_INVOKED
  248. #endif  // OWL_GLYPHBTN_H
  249.